home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 2108 / 2108.xpi / components / stylishCommandLine.js next >
Text File  |  2009-03-16  |  4KB  |  125 lines

  1. const nsIAppShellService    = Components.interfaces.nsIAppShellService;
  2. const nsISupports           = Components.interfaces.nsISupports;
  3. const nsICategoryManager    = Components.interfaces.nsICategoryManager;
  4. const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
  5. const nsICommandLine        = Components.interfaces.nsICommandLine;
  6. const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
  7. const nsIFactory            = Components.interfaces.nsIFactory;
  8. const nsIModule             = Components.interfaces.nsIModule;
  9. const nsIWindowWatcher      = Components.interfaces.nsIWindowWatcher;
  10.  
  11. const clh_contractID = "@mozilla.org/commandlinehandler/general-startup;1?type=stylish";
  12. const clh_CID = Components.ID("{639A2E30-078F-11DE-9C63-BC2A56D89593}");
  13. const clh_category = "m-stylish";
  14.  
  15. /**
  16.  * The XPCOM component that implements nsICommandLineHandler.
  17.  * It also implements nsIFactory to serve as its own singleton factory.
  18.  */
  19. const myAppHandler = {
  20.   /* nsISupports */
  21.   QueryInterface : function clh_QI(iid)
  22.   {
  23.     if (iid.equals(nsICommandLineHandler) ||
  24.         iid.equals(nsIFactory) ||
  25.         iid.equals(nsISupports))
  26.       return this;
  27.  
  28.     throw Components.results.NS_ERROR_NO_INTERFACE;
  29.   },
  30.  
  31.   /* nsICommandLineHandler */
  32.  
  33.     handle: function(commandLine) {
  34.         var index = commandLine.findFlag("stylish-disable", false);
  35.         if (index > -1) {
  36.             var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch)
  37.             prefs.setBoolPref("extensions.stylish.styleRegistrationEnabled", false);
  38.             commandLine.removeArguments(index, index);
  39.         }
  40.     },
  41.  
  42.     helpInfo: "  -stylish-disable               Turn off style registration in Stylish\n",
  43.  
  44.   /* nsIFactory */
  45.  
  46.   createInstance : function clh_CI(outer, iid)
  47.   {
  48.     if (outer != null)
  49.       throw Components.results.NS_ERROR_NO_AGGREGATION;
  50.  
  51.     return this.QueryInterface(iid);
  52.   },
  53.  
  54.   lockFactory : function clh_lock(lock)
  55.   {
  56.     /* no-op */
  57.   }
  58. };
  59.  
  60. /**
  61.  * The XPCOM glue that implements nsIModule
  62.  */
  63. const myAppHandlerModule = {
  64.   /* nsISupports */
  65.   QueryInterface : function mod_QI(iid)
  66.   {
  67.     if (iid.equals(nsIModule) ||
  68.         iid.equals(nsISupports))
  69.       return this;
  70.  
  71.     throw Components.results.NS_ERROR_NO_INTERFACE;
  72.   },
  73.  
  74.   /* nsIModule */
  75.   getClassObject : function mod_gch(compMgr, cid, iid)
  76.   {
  77.     if (cid.equals(clh_CID))
  78.       return myAppHandler.QueryInterface(iid);
  79.  
  80.     throw Components.results.NS_ERROR_NOT_REGISTERED;
  81.   },
  82.  
  83.   registerSelf : function mod_regself(compMgr, fileSpec, location, type)
  84.   {
  85.     compMgr.QueryInterface(nsIComponentRegistrar);
  86.  
  87.     compMgr.registerFactoryLocation(clh_CID,
  88.                                     "myAppHandler",
  89.                                     clh_contractID,
  90.                                     fileSpec,
  91.                                     location,
  92.                                     type);
  93.  
  94.     var catMan = Components.classes["@mozilla.org/categorymanager;1"].
  95.       getService(nsICategoryManager);
  96.     catMan.addCategoryEntry("command-line-handler",
  97.                             clh_category,
  98.                             clh_contractID, true, true);
  99.   },
  100.  
  101.   unregisterSelf : function mod_unreg(compMgr, location, type)
  102.   {
  103.     compMgr.QueryInterface(nsIComponentRegistrar);
  104.     compMgr.unregisterFactoryLocation(clh_CID, location);
  105.  
  106.     var catMan = Components.classes["@mozilla.org/categorymanager;1"].
  107.       getService(nsICategoryManager);
  108.     catMan.deleteCategoryEntry("command-line-handler", clh_category);
  109.   },
  110.  
  111.   canUnload : function (compMgr)
  112.   {
  113.     return true;
  114.   }
  115. };
  116.  
  117. /* The NSGetModule function is the magic entry point that XPCOM uses to find what XPCOM objects
  118.  * this component provides
  119.  */
  120. function NSGetModule(comMgr, fileSpec)
  121. {
  122.   return myAppHandlerModule;
  123. }
  124.  
  125.